home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / doc / ptr_read.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  70 lines

  1. ; PTR_READ accepts one argument, a named variable in which 
  2. ; to return the pointer that points at the beginning of the list.
  3.  
  4. PRO ptr_read, first
  5.  
  6. ; Initialize the input string variable.
  7.  
  8. newstring = ''
  9.  
  10. ; Create an anonymous strucutre to contain list elements. Note that 
  11. ; the next field is initialized to be a null pointer.
  12.  
  13. llist = {name:'', next:PTR_NEW()}
  14.  
  15. ; Print instructions for this program.
  16.  
  17. PRINT, 'Enter a list of names.'
  18. PRINT, 'Enter a period (.) to stop list entry.'
  19.  
  20. ; Continue accepting input until a period is entered.
  21.  
  22. WHILE newstring NE "." DO BEGIN
  23.  
  24.   ; Read a new string from the key board.
  25.  
  26.   READ, newstring, PROMPT='Enter string: '
  27.  
  28.   IF newstring NE '.' THEN BEGIN
  29.  
  30.     ; Check to see if a pointer called _first_ exists. If not, this
  31.     ; is the first element. Create a pointer called _first_ and
  32.     ; initialize it to be a list element. Create a second pointer
  33.     ; to the heap variable pointed at by _first_.
  34.  
  35.     IF NOT(PTR_VALID(first)) THEN BEGIN
  36.        first = PTR_NEW(llist)
  37.        current = first
  38.     ENDIF
  39.       
  40.     ; Create a pointer to the next list element.
  41.  
  42.     next = PTR_NEW({name:'', next:PTR_NEW()})
  43.  
  44.     ; Set the name field of _current_ to the input string.
  45.       
  46.     (*current).name = newstring
  47.  
  48.     ; Set the next field of _current_ to the pointer
  49.     ; to the next list element.
  50.  
  51.     (*current).next = next
  52.  
  53.     ; Copy the pointer to _current_.
  54.  
  55.     last = current
  56.  
  57.     ; Make _next_ the current pointer.
  58.  
  59.     current = next
  60.   
  61.   ENDIF
  62.  
  63. ENDWHILE
  64.  
  65. ; Set the _next_ field of the last element to the null pointer.
  66.  
  67. IF PTR_VALID(last) THEN (*last).next = PTR_NEW()
  68.  
  69. END
  70.